/*
 * SpiderpigOS
 * Copyright (C) 2009 - 2010 Davide Gessa
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef ARCH_H
#define ARCH_H

#include <types.h>

/* system arch settings, passed to main from each arch _start() */
#define VIDEO_MODE_TEXT		0
#define VIDEO_MODE_GRAPH	1

typedef struct
{	
	uint8_t video_mode;
	uint32_t video_x;
	uint32_t video_y;
	uint32_t video_depth;
	
	uint32_t *initram_pointer;
	uint32_t initram_size; 
	
	uint64_t mem_size;
} arch_info_t;

arch_info_t arch_info;

/* system timedate */
typedef struct
{
	uint8_t hours;			///< Ora
	uint8_t minutes;		///< Minuti
	uint8_t seconds;		///< Secondi
	uint8_t month;			///< Mese
	uint8_t day;			///< Giorno
	uint8_t year;			///< Anno
} clock_data_t;


clock_data_t clock_data;	///< Data e ora globali


/* stdio */
void arch_kputch(uint8_t, int16_t, int16_t);
uint16_t arch_kgetch();
void arch_ksetcl(uint16_t);
uint16_t arch_kgetcl();
void arch_kclear();


/* mem */
uint64_t arch_mem_total();


/* input ouput on ports */
void io_outb(uint16_t, uint8_t);
uint8_t io_inb(uint16_t);
void io_outw(uint16_t, uint16_t);
uint16_t io_inw(uint16_t);
void io_outd(uint16_t, uint32_t);
uint32_t io_ind(uint16_t);
void io_outl(uint16_t, uint64_t);
uint64_t io_inl(uint16_t);


/* handler */
#ifdef X86
	#include <../arch/x86/archinc.h>

	#define HANDLER_TIMER		0
	#define HANDLER_KEYBOARD	1
	//#define HANDLER_MOUSE		2

	void handler_reg(uint8_t, void (*)(regs_t));
	void handler_unreg(uint8_t);
#endif

/* timer and clock */
void arch_sleep(uint32_t);
uint32_t arch_get_clock();
uint32_t arch_get_tick();



/* arch init */
uint8_t arch_init();
void arch_shutdown();
void arch_reboot();
void arch_standby();


/* multi cpu */
#define CPU_USED		2
#define CPU_READY		1
#define CPU_SPLEEP		3
#define CPU_NOTPRESENT	0

uint32_t cpu_get_state(uint32_t);
uint32_t cpu_get_free();
uint32_t cpu_stop(uint32_t);
uint32_t cpu_num();
uint32_t cpu_exec(uint32_t, void *);
uint32_t cpu_whake(uint32_t);
uint32_t cpu_sleep(uint32_t);
uint32_t cpu_reset(uint32_t);
uint32_t cpu_get_id();

#endif
